
#include <android/log.h>

namespace glf {

void AndroidEnableAccelerometer(bool enable, float frequency);

InputManager::Impl* gImpl = 0;
	
const int sKdHandledEvents[] = {
	
};

const int sKdGameKeysMapping[] = {
	
};

const int sKdPhoneKeysMapping[] = {
	
};

struct InputManager::Impl : public input::ImplBase {

	Keyboard mKeyboard;
	Mouse mMouse;
	IPhoneController mController;
	
	//AccelerometerDelegate* mAccDelegate;

	Impl(InputManager& inputMgr) :
		ImplBase(inputMgr) {
		gImpl = this;

		//mAccDelegate = [AccelerometerDelegate alloc];
		
		EnableAccelerometer(true, 0.1f);
	}
	
	void EnableAccelerometer(bool enable, float frequency) {
		AndroidEnableAccelerometer(enable, frequency);
		mIsAccelerometerEnabled = enable;
	}
	
	~Impl() {
		EnableAccelerometer(false, 0.f);
	}
	
	void AccelerationEvent(float x, float y, float z) {
		if(mIsAccelerometerEnabled)
			mController.RaiseAccelerometerEvent(x, y, z);
	}

	void UpdateEvent() {
		
	}

	void UpdateFrame() {
	}
 
	Keyboard& GetKeyboard(uint idx) {
		return mKeyboard;
	}
	Mouse& GetMouse(uint idx) {
		return mMouse;
	}
	Gamepad& GetGamepad(uint idx) {
		return mController;
	}

	size_t GetKeyboardCount() const
	{
		return 1;
	}

	size_t GetMouseCount() const
	{
		return 1;
	}

	size_t GetGamepadCount() const
	{
		return 1;
	}

};

// Called from java sensor manager event callback
void AndroidAccelerometerEvent(float ax, float ay, float az)
{
	if(gImpl)
		gImpl->AccelerationEvent(ax, ay, az);
}

} //namespace glf
